#include <iostream>
#include "Camera.h"

Camera::Camera(vec3 pos, vec3 lookat)
{
    this->pos.x = this->pos.x;
    this->pos.y = this->pos.y;
    this->pos.z = this->pos.z;
    this->forward.x = lookat.x;
    this->forward.y = lookat.y;
    this->forward.z = lookat.z;
}

Camera::Camera(vec3 pos)
{
    this->pos.x = pos.x;
    this->pos.y = pos.y;
    this->pos.z = pos.z;
    forward.x = 0;
    forward.y = -0.5;
    forward.z = 0;
    //ctor
}

void    Camera::move(vec3 coord)
{
    //std::cout << "cam forward : " << forward << " cam pos : " << this->pos << std::endl;
    pos.x += coord.x;
    pos.y += coord.y;
    pos.z += coord.z;
}

void    Camera::update()
{
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
        this->rotatex(0.05);
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
        this->rotatex(-0.05);
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Num8))
        this->rotatez(0.01);
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Num2))
        this->rotatez(-0.01);
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
        this->move(vec3(this->forward.x * -0.1, this->forward.y * -0.1, this->forward.z * -0.05));
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
        this->move(this->forward * 0.05f);
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::PageUp))
        this->move(vec3(0,0,1) * 0.1f);
    if (sf::Keyboard::isKeyPressed(sf::Keyboard::PageDown))
        this->move(vec3(0,0,-1) * 0.1f);
}

void    Camera::draw()
{
    //std::cout << "cam x " << lookat.x << " cam y " << lookat.y << " cam z " << lookat.z << std::endl;
    gluLookAt(pos.x,pos.y,pos.z,pos.x + forward.x,pos.y + forward.y,pos.z + forward.z,0,0,1);
}

Camera::~Camera()
{
    //dtor
}
